<template>
	<view class="content" v-if="pageshow">
		<view class="padding">
			<view class="">
				<!-- 订单状态 -->
				<!-- state -> 1=待付款,2=待成团,3=待发货,4=待收货,5=待评价,6=已完成 -->
				<view class="bigtext" v-if="orderDetail.state==1">等待买家付款</view>
				<view class="bigtext" v-if="orderDetail.state==2">待分享</view>
				<view class="bigtext" v-if="orderDetail.state==3">等待商家发货</view>
				<view class="bigtext" v-if="orderDetail.state==4">等待买家收货</view>
				<view class="bigtext" v-if="orderDetail.state==5">待评价</view>
				<view class="bigtext" v-if="orderDetail.state==6">已完成</view>
				<view class="bigtext" v-if="orderDetail.state==-1">已取消</view>
			</view>
			<!--订单时间状态  -->
			<view class="margin_top1">
				<view class="strongtext" v-if="orderDetail.state==1">待用户支付~</view>
				<view class="strongtext" v-if="orderDetail.state==2">分享购买商品，其他用户参加后即可成团~</view>
				<view class="strongtext " v-if="orderDetail.state==3">请您耐心等待商家发货~</view>
				<view class="strongtext " v-if="orderDetail.state==4">物流运输中~</view>
				<view class="strongtext " v-if="orderDetail.state==5">期待您的评价~</view>
				<view class="strongtext " v-if="orderDetail.state==6">感谢您的支持，欢迎下次购买~</view>
				<view class="strongtext " v-if="orderDetail.state==-1">您已取消此订单~</view>
			</view>
			<!-- 地址 -->
			<view class="padding ffffff border_2 margin_top">
				<view class="flexbetween">
					<view class>
						<view class="flexleft">
							<view class=" word_baiba black margin_right3">{{orderDetail.orderaddress.name}}</view>
							<view class=" word_baiba black">{{orderDetail.orderaddress.mobile}}</view>
						</view>
						<view class="huisetext margin_top2">
							{{orderDetail.orderaddress.region}}{{orderDetail.orderaddress.address}}
						</view>
					</view>
				</view>
			</view>
			<!-- 商品 -->
			<view class="ffffff padding border_2 margin_top">
				<view class="flexleft">
					<image class="imgShop margin_right1" src="/static/image/mine/dianpuRed.png" mode="widthFix"></image>
					<view class="color_ling text_z margin_right1">{{orderDetail.shop.shop_name}}</view>
					<u-icon name="arrow-right" color="rgba(153, 153, 153, 1)" size="12"></u-icon>
				</view>
				<view class=" xiahuax margin_top" v-for="item in orderDetail.ordergoods" :key="item.id"
					@click="goGoodsInfo(item.goods_id)">
					<view class="flexbetween">
						<view class="shilitu">
							<image :src="item.goods_image_text" mode="widthFix"></image>
						</view>
						<view class="" style="width: 74%;">
							<view class="ershib yhxiank">{{item.goods_name}}</view>
							<view class="margin_top1 white">{{item.sku}}</view>
							<view class="flexbetween margin_top1">
								<view class="qianshu">¥{{orderDetail.activity_type==1?item.alone_price:item.price}}</view>
								<view class="shuliang">X{{item.goods_num}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 商品详情 -->
			<view class="paddingbom">
				<view class="ffffff padding border_2 margin_top">
					<view class="flexbetween">
						<view class="tuihuo">商品金额</view>
						<view class="text_x" style="color:rgba(243, 39, 28, 1);">¥{{orderDetail.total_price}}</view>
					</view>
					<view class="flexbetween margin_top">
						<view class="tuihuo">运费</view>
						<view class="huisetext">￥{{orderDetail.logistics_price}}</view>
					</view>
					<view class="flexbetween margin_top">
						<view class="tuihuo">订单编号</view>
						<view class="huisetext">{{orderDetail.order_no}}</view>
					</view>
					<view class="flexbetween margin_top">
						<view class="tuihuo">下单时间</view>
						<view class="huisetext">{{orderDetail.createtime_text}}</view>
					</view>
					<view class="flexbetween margin_top">
						<view class="tuihuo">支付方式</view>
						<view class="huisetext">{{orderDetail.pay_type_text}}</view>
					</view>
					<view class="flexbetween margin_top" v-if="orderDetail.remarks">
						<view class="tuihuo">备注</view>
						<view class="huisetext">{{orderDetail.remarks}}</view>
					</view>
				</view>
			</view>
			<!-- 固定底部 -->
			<view class="gudingdb ffffff">
				<view class="flexright ">
					<view class="huisebtn" v-show="orderDetail.can_cancel" @click.stop="cancelorder(orderDetail.id)">
						取消订单
					</view>
					<view class="huangsebtn margin_left3" v-show="orderDetail.can_pay"
						@click.stop="atoncePay(orderDetail)">立即付款</view>
					<view class="huisebtn margin_left3" v-show="orderDetail.can_buyfull"
						@click.stop="atonceAllPay(orderDetail)">全款购买</view>
					<view class="huangsebtn margin_left3" v-show="orderDetail.can_share"
						@click.stop="onceShare(orderDetail.id)">立即分享</view>
					<view class="huisebtn margin_left3" v-show="orderDetail.can_express"
						@click.stop="goLogisticsInfo(orderDetail.id)">查看物流</view>
					<view class="huisebtn margin_left3" v-show="orderDetail.can_refund"
						@click.stop="goApplyRefund(orderDetail.id)">退货/售后</view>
					<view class="huangsebtn margin_left3" v-show="orderDetail.can_receipt"
						@click.stop="suresh(orderDetail.id)">确认收货</view>
					<view class="huangsebtn margin_left3" v-show="orderDetail.can_comment"
						@click.stop="evaluate(orderDetail.id)">立即评价</view>
					<view class="huisebtn margin_left3" v-show="orderDetail.can_del"
						@click.stop="deletorder(orderDetail.id)">删除订单</view>
				</view>
			</view>
		</view>
		<u-popup :show="show" round="20" mode="center" @close="show=false">
			<view class="popupBox">
				<view class="title">分享拼单</view>
				<view class="text_g color_ling margin_top4">
					还差<text
						style="color: rgba(243, 39, 28, 1);">{{shareInfo.groupbuyingdata.buying_total_num - shareInfo.groupbuyingdata.buying_now_num}}</text>人，赶快邀请好友拼单吧
				</view>
				<view class="margin_top5 flexbetween">
					<view class="text" @click="wxShareFriends">
						<image class="imgBox" src="/static/image/home/weixin.png" mode="widthFix"></image>
						<view class="text_b color_ling margin_top2">微信好友</view>
					</view>
					<view class="text" @click="qqShareFriends">
						<image class="imgBox" src="/static/image/home/QQ.png" mode="widthFix"></image>
						<view class="text_b color_ling margin_top2">QQ好友</view>
					</view>
				</view>
			</view>
		</u-popup>
		
		
		
		<!-- 物流单号弹出框 -->
		<u-popup :show="wlinfoShow" mode="center" @close="wlinfoShow=false" :round="15">
			<view class="text dan">
				<text class="wuliu">物流单号</text>
				<view class="zhongtong">
					<view class="">{{express_name}}</view>
					<view class="text margin_top1">{{express_no}}</view>
				</view>
				<view class="fuzhi">
					<view class="copy" @click="copy">点击复制</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				show: false,
				shareInfo: {
					groupbuyingdata: {}
				}, //拼团详情
				orderID: '', // 订单 id
				orderDetail: {}, // 订单详情内容
				pageshow: false,
				qrcodeurl: '',
				express_name:'',
				express_no:'',
				wlinfoShow:false,
			}
		},
		onLoad(options) {
			let _this = this
			_this.orderID = options.id
		},
		onShow() {
			let _this = this
			_this.getOrderInfo()
		},
		methods: {
			goLogisticsInfo(id) { //查看物流
				// uni.navigateTo({
				// 	url: "/pages_mine/logisticsInfo?type=3&id=" + id
				// })
				
				
				let _this=this;
				var url = "/api/goods_order/express"
				var data = {
					order_id:id
				}
				
				httpRequest.request(url, 'POST', data, false, false, true).then(res => {
					
					
					if(res.code==1){
						
						
						
						_this.express_no=res.data.express_no;
						_this.express_name=res.data.express_name;
						
						_this.wlinfoShow = true;
					}else{
						httpRequest.toast(res.msg)
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				}).catch(err=>{
					httpRequest.toast(err.msg)
				})
			},
			
			
			// 点击复制
			copy() {
				let value = "物流名称：" + this.orderDetail.express_name + " 单号：" + this.orderDetail.express_no
				uni.setClipboardData({
					data: value, //要被复制的内容
					success: () => {
						//复制成功的回调函数
						httpRequest.toast("复制成功")
						this.show = false
					}
				});
			},
			goApplyRefund(id) { //退货/售后
				uni.navigateTo({
					url: "/pages_mine/applyRefund?id=" + id
				})
			},
			// 获取订单详情
			getOrderInfo() {
				let _this = this
				httpRequest.request('/api/goods_order/orderdetail', 'GET', {
					order_id: _this.orderID
				}).then(res => {
					if (res.code == 1) {
						_this.orderDetail = res.data
						this.pageshow = true
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			goGoodsInfo(id) { //商品详情
				uni.navigateTo({
					url: "/pages_index/goodsInfo?id=" + id
				})
			},
			// 取消订单
			cancelorder() {
				httpRequest.modal('提示', '确定取消当前订单吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/goods_order/cancelorder', 'POST', {
							order_id: this.orderID,
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg);
							if (res.code == 1) {
								setTimeout(() => {
									uni.navigateBack(1)
								}, 500)
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			atoncePay(item) { // 支付
				let obj = {
					order_id: this.orderID,
					total_price: item.total_price
				}
				uni.navigateTo({
					url: '/pages_index/payment?msg1=' + encodeURIComponent(JSON.stringify(obj))
				})
			},
			atonceAllPay(item) { // 全款购买
				let obj = {
					order_id: this.orderID,
				}
				uni.navigateTo({
					url: '/pages_index/payment?msg2=' + encodeURIComponent(JSON.stringify(obj))
				})
			},
			onceShare(id) { //立即分享
				let _this = this;
				httpRequest.request("/api/goods_order/groupshare", 'POST', {
					order_id: id
				}, false, false, true).then(res => {
					if (res.code == 1) {
						_this.shareInfo = res.data
					} else {
						httpRequest.toast(res.msg);
					}
					_this.show = true
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			wxShareFriends() { //微信分享
				let _this = this
				uni.share({
					provider: "weixin",
					type: 0,
					title: "微信分享",
					href: "https://hongnwh.yuntaiqikeji.com/h5",
					scene: "WXSceneSession",
					summary: "分享测试！！！",
					imageUrl: "www.wanxiangshide.xyz/uploads/20230722/68c2959eb3a63faff5248380f80bc5c1.png",
					success: function(res) {
						console.log("success:" + JSON.stringify(res));
						httpRequest.toast("分享成功！");
						_this.show = false
					},
					fail: function(err) {
						console.log("fail:" + JSON.stringify(err));
					}
				});
			},
			qqShareFriends() { //QQ分享
				let _this = this
				let url = "https://hongnwh.yuntaiqikeji.com/h5"
				uni.share({
					provider: "qq",
					type: 1,
					title: "qq分享",
					href: url,
					summary: "分享测试！！！",
					// imageUrl:"www.wanxiangshide.xyz/uploads/20230722/68c2959eb3a63faff5248380f80bc5c1.png",
					success: function(res) {
						console.log("success:" + JSON.stringify(res));
						httpRequest.toast("分享成功！");
						_this.show = false
					},
					fail: function(err) {
						console.log("fail:" + JSON.stringify(err));
					}
				});
			},
			// 确认收货
			suresh() {
				httpRequest.modal('提示', '请再次确认', true, (res) => {
					if (res) {
						httpRequest.request('/api/goods_order/receipt', 'POST', {
							order_id: this.orderID,
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg);
							if (res.code == 1) {
								setTimeout(() => {
									uni.navigateBack(1)
								}, 500)
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			atoncePay() {
				let obj = {
					id: this.orderDetail.order_pay_no, // 支付订单号
					pay_price: this.orderDetail.pay_price, // 支付金额
				}
				uni.navigateTo({
					url: '/pages_index/zhifu?msg=' + encodeURIComponent(JSON.stringify(obj))
				})
			},
			// 删除订单
			deletorder() {
				httpRequest.modal('提示', '确定删除当前订单吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/goods_order/del', 'POST', {
							order_id: this.orderID,
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg);
							if (res.code == 1) {
								setTimeout(() => {
									uni.navigateBack(1)
								}, 500)
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			// 跳转 立即评价
			evaluate(id) {
				uni.navigateTo({
					url: "/pages_mine/reportEvaluate?type=1&id=" + id
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.imgShop {
		width: 26.62rpx;
		height: 24rpx;
	}

	.dan {
		width: 80vw;
		padding: 64rpx 40rpx 0rpx 40rpx;
	}

	.tuihuo {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
	}

	.money_tui {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #D48B39;
	}

	.order {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	.hexiao {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
	}

	.white {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.erwie {
		width: 169rpx;
		height: 169rpx;
	}

	.code {
		padding: 30rpx 30rpx;
		margin-top: 30rpx;
		background-color: #fff;
	}

	::v-deep.u-safe-area-inset-bottom {
		padding-bottom: 0;
		padding-bottom: constant(safe-area-inset-bottom);
	}

	.fuzhi {
		padding: 0rpx 100rpx;
	}

	.copy {
		padding: 20rpx 40rpx;
		border-radius: 51rpx;
		background-color: rgba(212, 139, 57, 1);
		margin-top: 109rpx;
		color: #fff;
	}

	.dan {
		padding: 64rpx 40rpx 64rpx 40rpx;
	}

	.zhongtong {
		margin-top: 87rpx;
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
		padding: 34rpx 82rpx;
		border: 1rpx solid rgba(223, 223, 223, 1);
		border-radius: 10rpx;
	}

	.wuliu {
		font-size: 40rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	.strongtext {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.bigtext {
		font-size: 34rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #333333;
	}

	.xzqianshu {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: rgba(212, 139, 57, 1);
	}

	.huangsebtn {
		border: 2rpx solid rgba(243, 39, 28, 1);
		width: 170rpx;
		height: 67rpx;
		display: flex;
		border-radius: 120rpx;
		align-items: center;
		justify-content: center;
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: rgba(243, 39, 28, 1);
	}

	.huisebtn {
		border: 2rpx solid #666666;
		width: 170rpx;
		height: 67rpx;
		display: flex;
		border-radius: 120rpx;
		align-items: center;
		justify-content: center;
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.shuliang {
		font-size: 26rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #999999;
	}

	.ershib {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.shilitu {
		width: 134rpx;
		height: 128rpx;
		border-radius: 14rpx;
 overflow: hidden;
		image {
			width: 100%;
			height: 100%;
			border-radius: 14rpx;
		}
	}

	.qianshu {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: rgba(243, 39, 28, 1);
	}

	.huisetext {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.yhxiank {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.paddingbom {
		padding-bottom: 150rpx;
	}

	.popupBox {
		padding: 65rpx 95rpx;

		.title {
			font-size: 40rpx;
			font-family: PingFang SC-Heavy, PingFang SC;
			font-weight: 800;
			color: #000000;
			text-align: center;
		}

		.imgBox {
			width: 112rpx;
			height: 112rpx;
		}
	}
</style>